#ifndef QAV_DECODER_H
#define QAV_DECODER_H

#include <QtAV/QtAV_Global.h>

class QByteArray;
struct AVCodecContext;
struct AVFrame;

namespace QtAV {

class AVDecoderPrivate;
class Q_AV_EXPORT AVDecoder
{
    DPTR_DECLARE_PRIVATE(AVDecoder)
public:
    AVDecoder();
    virtual ~AVDecoder();
    /*
     * default is open FFmpeg codec context
     * codec config must be done before open
     */
    virtual bool open();
    virtual bool close();
    bool isOpen() const;
    void flush();
    void setCodecContext(AVCodecContext* codecCtx); //protected
    AVCodecContext* codecContext() const;
    // force a codec
    void setCodecName(const QString& name);
    QString codecName() const;

    //? low resolution decoding, 0: normal, 1-> 1/2 size, 2->1/4 size
    void setLowResolution(int lowres);
    int lowResolution() const;
    // -1: auto detect by QThread::idealThreadCount(). 0: set by ffmpeg(default)
    void setDecodeThreads(int threads);
    int decodeThreads() const;
    void setThreadSlice(bool s);
    /*not available if AVCodecContext == 0*/
    bool isAvailable() const;
    virtual bool prepare(); //if resampler or image converter set, call it
    virtual bool decode(const QByteArray& encoded) = 0; //decode AVPacket?
    QByteArray data() const; //decoded data

protected:
    AVDecoder(AVDecoderPrivate& d);

    DPTR_DECLARE(AVDecoder)
};

} //namespace QtAV
#endif // QAV_DECODER_H
